define(
	[
	appBasePath + '/scripts/module.js',
	],
	function (substanceModule) {
    'use strict';
    substanceModule.controller('Substance.SubjectTestController', [
        '$scope', '$http', '$timeout', '$compile', '$filter', 'Substance.SubjectService', '$state', 
        function ($scope, $http, $timeout, $compile, $filter, service, $state) {
        	
        	// $scope.map = {"subject_name":"办公用品","company_str":"40001","account_id":"","is_contain_tax":"y","account_name":"厦门万达国际电影城有限公司","amount":"210","cost_organ_name":"行政部","is_company":"y","tax_amount":"10","organ_name":"行政部","nusage":"摘要","pay_bank_no":"592902755910301","no_tax_amount":"200"};
        	$scope.map = {"amount":"2000","subject_list":[{"amount":"1600.00","subject_name":"差旅费","cost_organ_name":"行政部","nusage":"这个报差旅","organ_name":"行政部"},{"amount":"200.00","subject_name":"办公用品","cost_organ_name":"行政部","nusage":"这个报办公用品","organ_name":"IT部"}],"company_str":"40001","account_id":"","cost_organ_name":"行政部","tax_list":[{"is_contain_tax":"n","tax_amount":"0","no_tax_amount":"0"},{"is_contain_tax":"y","tax_amount":"52.43","no_tax_amount":"1747.57"}],"pay_list":[{"amount":"1000","is_company":"y","account_name":"厦门万达国际电影城有限公司"},{"amount":"800.00","is_company":"n","account_name":"李丽丽"}],"organ_name":"行政部","pay_bank_no":"592902755910301"};
        	for (var i=0; i<2; i++) {
        		$scope.map.subject_list.push({});
            	$scope.map.tax_list.push({});
            	$scope.map.pay_list.push({});
        	}
        	
        	$scope.create = function(valid) {
        		if (!valid) {
        			alert("验证失败");
        			return false;
        		}
        		var map = $scope.map;
        		var data = {
        				cost_organ_name: map.cost_organ_name,
        				organ_name: map.organ_name,
        				pay_bank_no: map.pay_bank_no,
        				amount: map.amount,
        				company_str:map.company_str,
        				account_id: map.account_id,
        				subject_list:[],
        				tax_list : [],
        				pay_list : []
        		};
        		var sl = $(".subject_list");
        		sl.each(function(i) {
        			var d = {};
        			d['cost_organ_name'] = $("input:eq(0)", sl[i]).val();
        			d['organ_name'] = $("input:eq(1)", sl[i]).val();
        			d['subject_name'] = $("input:eq(2)", sl[i]).val();
        			d['amount'] = $("input:eq(3)", sl[i]).val();
        			d['nusage'] = $("input:eq(4)", sl[i]).val();
        			if (d['cost_organ_name']) {
        				data.subject_list.push(d);
        			}
        		});
        		
        		var tl = $(".tax_list");
        		tl.each(function(i) {
        			var d = {};
        			d['tax_amount'] = $("input:eq(0)", tl[i]).val();
        			d['no_tax_amount'] = $("input:eq(1)", tl[i]).val();
        			d['is_contain_tax'] = $("input:eq(2)", tl[i]).val();
        			if (d['tax_amount'] != '') {
        				data.tax_list.push(d);
        			}
        		});
        		
        		var pl = $(".pay_list");
        		pl.each(function(i) {
        			var d = {};
        			d['account_name'] = $("input:eq(0)", pl[i]).val();
        			d['amount'] = $("input:eq(1)", pl[i]).val();
        			d['is_company'] = $("input:eq(2)", pl[i]).val();
        			if (d['account_name']) {
        				data.pay_list.push(d);
        			}
        		});
        		
        		service.info(data).then(function(data) {
        			if (data && data.success) {
        				$scope.testResult = data.data;
        				$("#test-info").show();
        				$("#test-info .glyphicon-remove").bind("click",function(){
            			    $(".admin-add").hide();
            			});
            			  $("#test-info .btn-concel").bind("click",function(){
            			    $("#setadmin").hide();
            			  });
        			} else {
        				$scope.errorMsg(data);
        			}  			
        		});
        	};
        	
        }
        
        
    ]);
});